﻿<phone:PhoneApplicationPage
    x:Class="DepSoft.Mobile.WP8.FollwIt.View.FollwItPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:CimbalinoConverters="clr-namespace:Cimbalino.Phone.Toolkit.Converters;assembly=Cimbalino.Phone.Toolkit"
    xmlns:converters="clr-namespace:DepSoft.Mobile.WP8.FollwIt.Converters"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP8"
    xmlns:behaviors="clr-namespace:Cimbalino.Phone.Toolkit.Behaviors;assembly=Cimbalino.Phone.Toolkit"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="False"
    DataContext="{Binding FollwIt, Source={StaticResource Locator}}"    
    >

    <phone:PhoneApplicationPage.Resources>
        <converters:NullVisibilityConverter x:Key="NullVisibilityConverter" />
        <converters:InverseVisibilityConverter x:Key="InverseVisibilityConverter" />
        <CimbalinoConverters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    </phone:PhoneApplicationPage.Resources>       

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <command:EventToCommand Command="{Binding ViewLoadedCommand}"
                                    PassEventArgsToCommand="True"
                                    IsEnabled="{Binding ViewLoadedCommandEnabled}"/>
        </i:EventTrigger>
        <i:EventTrigger EventName="BackKeyPress">
            <command:EventToCommand Command="{Binding BackKeyPressCommand}" PassEventArgsToCommand="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <i:Interaction.Behaviors>
        <behaviors:AutoFocusBehavior/>
    </i:Interaction.Behaviors>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <MediaElement x:Name="Video"
                      Grid.RowSpan="2"
                      Source="/Assets/MovieCountdown.wmv"
                      MediaEnded="OnMediaEnded"
                      AutoPlay="True"
                      IsHitTestVisible="False"
                      />

        <Image x:Name="VideoBackground"
               Source="/Assets/MovieCountdown.png"
               Visibility="Collapsed"
               IsHitTestVisible="False"
               Grid.RowSpan="2"
               />

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel Grid.Row="0" Margin="12,17,12,28">
            <TextBlock Text="FOLLW.IT" Margin="12,0" Style="{StaticResource PhoneTextNormalStyle}" FontWeight="SemiBold" Foreground="{StaticResource DarkPhoneForegroundBrush}"/>
            <TextBlock Text="connection" Margin="12,6,0,0" Style="{StaticResource PhoneTextTitle2Style}" Foreground="{StaticResource DarkPhoneForegroundBrush}"/>
        </StackPanel>

        <ProgressBar x:Name="ProgressBar"
                     Grid.Row="0"
                     IsIndeterminate="{Binding IsBusy}"
                     Margin="12,100,12,0"
                     Visibility="{Binding IsBusy, Converter={StaticResource BooleanToVisibilityConverter}}"
                     Foreground="{StaticResource DarkPhoneForegroundBrush}"
                     VerticalAlignment="Top"
                     />

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <StackPanel x:Name="LoginPanel"
                        Visibility="{Binding ElementName=LoggedinPanel, Path=Visibility, Converter={StaticResource InverseVisibilityConverter}}"
                        VerticalAlignment="Top" Margin="0,60,0,0">
                <TextBlock Text="username" Margin="12,0,0,0" Foreground="{StaticResource DarkPhoneForegroundBrush}" />
                <TextBox x:Name="UserName" Style="{StaticResource DarkThemeTextBoxStyle}"
                         Text="{Binding UserName, Mode=TwoWay}"/>
                <TextBlock Text="password" Margin="12,0,0,0" Foreground="{StaticResource DarkPhoneForegroundBrush}" />
                <PasswordBox Style="{StaticResource DarkThemePasswordBoxStyle}"
                             Password="{Binding Password, Mode=TwoWay}"/>
                <Button Content="connect" Background="#FF706868" BorderThickness="1" CacheMode="BitmapCache"
                        Command="{Binding AuthenticateCommand}"
                        Style="{StaticResource DarkThemeButtonStyle}"/>

                <Border Background="#CC706868"
                        BorderBrush="#CC706868"                        
                        BorderThickness="3"
                        Visibility="{Binding LoginFailed, Converter={StaticResource BooleanToVisibilityConverter}}"
                        Margin="12,12,12,0">
                    <TextBlock Text="Unable to log in with the given credentials... please try again!"
                               Margin="12"
                               Foreground="{StaticResource DarkPhoneForegroundBrush}" TextWrapping="Wrap" />
                </Border>
            </StackPanel>
            <StackPanel x:Name="LoggedinPanel"
                        Margin="0,60,0,0"
                        Visibility="{Binding Security, Converter={StaticResource NullVisibilityConverter}}">
                <Border Background="{StaticResource DarkPhoneInactiveBrush}"
                        Opacity="1"
                        BorderBrush="{StaticResource DarkPhoneInactiveBrush}"
                        BorderThickness="3"
                        Margin="12,0,12,12">
                    <StackPanel Margin="12">
                        <TextBlock Text="currently logged in as"
                                   Foreground="{StaticResource DarkPhoneForegroundBrush}" />
                        <TextBlock Text="{Binding Security.UserName}"
                                   Margin="0,12,0,0"
                                   FontSize="24"
                                   FontWeight="Bold"                                  
                                   Foreground="{StaticResource DarkPhoneForegroundBrush}" />
                    </StackPanel>
                </Border>
                <Button x:Name="DisconnectButton" Content="disconnect" Background="#FF706868" BorderThickness="1" CacheMode="BitmapCache"
                        Command="{Binding DisconnectCommand}"
                        Style="{StaticResource DarkThemeButtonStyle}"/>
            </StackPanel>
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>